🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / feature / firmware / src / commonMain / kotlin / org / meshtastic / feature / firmware / ota / FirmwareUpdateHelpers.kt
Displaying Raw • Download
feature/firmware/src/commonMain/kotlin/org/meshtastic/feature/firmware/ota/FirmwareUpdateHelpers.kt 2d20cd8a4708e2ef66e98d5259f3a97ec93f240a (2d20cd8a) Text, 2.73 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.firmware.ota
Tff7b72import T7ee787kotlinx.coroutines.delay
Tff7b72import T7ee787org.meshtastic.core.common.util.NumberFormatter
Tff7b72private Tff7b72const Tff7b72val Te6edf3PERCENT_MAX Tff7b72= T79c0ff1T79c0ff0T79c0ff0
Tff7b72private Tff7b72const Tff7b72val Te6edf3KIB_DIVISOR Tff7b72= T79c0ff1T79c0ff0T79c0ff2T79c0ff4f
T8b949e/**
* Formats firmware-transfer progress as a human-readable detail string, e.g. `"42% (12.3 KiB/s, ETA: 5s)"`.
*
* When [bytesPerSecond] is non-positive (no throughput sample yet) only the percentage is returned — no empty
* parentheses. Shared by the ESP32 OTA and Nordic DFU update handlers, which differ only in how they obtain the inputs.
*/
Tff7b72internal Tff7b72fun Td2a8ffformatTransferProgressTb4b4b4(Te6edf3progressTb4b4b4: Tffa657FloatTb4b4b4, Te6edf3totalBytesTb4b4b4: Tffa657IntTb4b4b4, Te6edf3bytesPerSecondTb4b4b4: Tffa657LongTb4b4b4)Tb4b4b4: Tffa657String Tb4b4b4{
Tff7b72val Te6edf3percent Tff7b72= Tb4b4b4(Te6edf3progress Tff7b72* Te6edf3PERCENT_MAXTb4b4b4)Tb4b4b4.Te6edf3toIntTb4b4b4(Tb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3bytesPerSecond Tff7b72<Tff7b72= T79c0ff0LTb4b4b4) Tff7b72return Ta5d6ff"Tffd700$Te6edf3percentTa5d6ff%Ta5d6ff"
Tff7b72val Te6edf3kibPerSecond Tff7b72= Te6edf3bytesPerSecondTb4b4b4.Te6edf3toFloatTb4b4b4(Tb4b4b4) Tff7b72/ Te6edf3KIB_DIVISOR
Tff7b72val Te6edf3bytesSent Tff7b72= Tb4b4b4(Te6edf3progress Tff7b72* Te6edf3totalBytesTb4b4b4)Tb4b4b4.Te6edf3toLongTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3etaSeconds Tff7b72= Tb4b4b4(Tb4b4b4(Te6edf3totalBytes Tff7b72- Te6edf3bytesSentTb4b4b4)Tb4b4b4.Te6edf3toFloatTb4b4b4(Tb4b4b4) Tff7b72/ Te6edf3bytesPerSecondTb4b4b4)Tb4b4b4.Te6edf3toIntTb4b4b4(Tb4b4b4)
Tff7b72return Ta5d6ff"Tffd700$Te6edf3percentTa5d6ff% (Tffd700${Te6edf3NumberFormatterTb4b4b4.Te6edf3formatTb4b4b4(Te6edf3kibPerSecondTb4b4b4, T79c0ff1Tb4b4b4)Tffd700}Ta5d6ff KiB/s, ETA: Tffd700${Te6edf3etaSecondsTffd700}Ta5d6ffs)Ta5d6ff"
Tb4b4b4}
T8b949e/**
* Runs [block] up to [attempts] times, returning the first successful [Result]. [onAttempt] fires before each attempt
* (1-based) for progress reporting, and [retryDelayMillis] is waited between tries (never after the last). If every
* attempt fails, returns the last failure so the caller can surface it however it likes (rethrow as-is vs. wrap in a
* domain exception).
*/
Tff7b72internal Tff7b72suspend Tff7b72fun Tff7b72<Te6edf3TTff7b72> Td2a8ffretryWithDelayTb4b4b4(
Te6edf3attemptsTb4b4b4: Tffa657IntTb4b4b4,
Te6edf3retryDelayMillisTb4b4b4: Tffa657LongTb4b4b4,
Te6edf3onAttemptTb4b4b4: Tb4b4b4(Te6edf3attemptTb4b4b4: Tffa657IntTb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4,
Te6edf3blockTb4b4b4: Te6edf3suspend Tb4b4b4(Te6edf3attemptTb4b4b4: Tffa657IntTb4b4b4) Tff7b72-Tff7b72> Te6edf3ResultTff7b72<Te6edf3TTff7b72>Tb4b4b4,
Tb4b4b4)Tb4b4b4: Te6edf3ResultTff7b72<Te6edf3TTff7b72> Tb4b4b4{
Tff7b72var Te6edf3lastErrorTb4b4b4: Te6edf3Throwable? Tff7b72= Tff7b72null
Tff7b72for Tb4b4b4(Te6edf3attempt Tff7b72in T79c0ff1.Tb4b4b4.Te6edf3attemptsTb4b4b4) Tb4b4b4{
Te6edf3onAttemptTb4b4b4(Te6edf3attemptTb4b4b4)
Tff7b72val Te6edf3result Tff7b72= Te6edf3blockTb4b4b4(Te6edf3attemptTb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3resultTb4b4b4.Te6edf3isSuccessTb4b4b4) Tff7b72return Te6edf3result
Te6edf3lastError Tff7b72= Te6edf3resultTb4b4b4.Te6edf3exceptionOrNullTb4b4b4(Tb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3attempt Tff7b72< Te6edf3attemptsTb4b4b4) Te6edf3delayTb4b4b4(Te6edf3retryDelayMillisTb4b4b4)
Tb4b4b4}
Tff7b72return Te6edf3ResultTb4b4b4.Te6edf3failureTb4b4b4(Te6edf3lastError Tff7b72?: Te6edf3IllegalStateExceptionTb4b4b4(Ta5d6ff"Ta5d6ffretryWithDelay: all Tffd700$Te6edf3attemptsTa5d6ff attempts failedTa5d6ff"Tb4b4b4)Tb4b4b4)
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.09s